import os
from dataclasses import dataclass
from typing import Optional

@dataclass
class Config:

    # PDF文件夹路径
    pdf_folder: str = "./pdf_files"

    # 文档问题文件夹路径
    question_folder: str = "./questions"

    # 问答对文件夹路径
    output_folder: str = "./results"

    # markdown文件夹路径
    markdown_folder: str = os.path.join(os.path.dirname(__file__), "markdown")

    # summary文件路径
    summary: str = os.path.join(os.path.dirname(__file__), "summary.json")

    # 大模型API配置
    api_key: str = ""
    api_endpoint: str = ""
    model_name: str = ""

    # 处理参数
    max_tokens: int = 65535
    temperature: float = 0.3
    timeout: int = 600

    def validate(self):
        """验证配置"""
        if not os.path.exists(self.pdf_folder):
            os.makedirs(self.pdf_folder, exist_ok=True)

        if not self.api_key or self.api_key == "your_api_key_here":
            raise ValueError("请设置正确的API密钥")

    def __post_init__(self):
        self.validate()